package org.sgr.money.manager.util;

public class MgrUtil {

	public static boolean validateNumber(int code, String strNumber, int decimalLen) {
		boolean flag = true;
		if ((code < 48 || code > 57) && code != 46) {
			//
			// not "0-9", ".", "back", "del", "home", "end"
			flag = false;
		} else if (code == 46) {
			if (strNumber.length() == 0 || strNumber.indexOf('.') > 0) {
				flag = false;
			}
		} else if (code >= 48 && code <= 57) {
			int i = strNumber.indexOf('.');
			if (i > 0 && (strNumber.length() - i > decimalLen)) {
				flag = false;
			}

		} else if (code != 8 && code != 127 && code < 16777217 && code > 16777224) {
			// not "back", "del", "home", "end", "<", ">", "up", "down"
			flag = false;
		}
		return flag;
	}

	public static boolean validateNull(String str) {
		boolean flag = (str == null || str.trim().equals(""));
		return flag;
	}

	public static boolean equal(Long l1, Long l2) {
		boolean flag = false;
		if (l1 == null && l2 == null) {
			flag = true;
		} else if (l1 != null && l1.equals(l2)) {
			flag = true;
		} else if (l1 == null && (l2.equals(l1) || l2.intValue() == 0)) {
			flag = true;
		} else if (l2 == null && (l1.equals(l2) || l1.intValue() == 0)) {
			// for access
			flag = true;
		}
		return flag;
	}
}
